package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.domain.ZhuanjiaBiandongDetail;
import com.ruoyi.system.domain.ZhuanjiaQushiquerenPici;
import com.ruoyi.system.mapper.ZhuanjiaBiandongDetailMapper;
import com.ruoyi.system.mapper.ZhuanjiaQushiquerenPiciMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ZhuanjiaQushiquerenMapper;
import com.ruoyi.system.domain.ZhuanjiaQushiqueren;
import com.ruoyi.system.service.IZhuanjiaQushiquerenService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 专家去世确认Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-30
 */
@Service
public class ZhuanjiaQushiquerenServiceImpl implements IZhuanjiaQushiquerenService 
{
    @Autowired
    private ZhuanjiaQushiquerenMapper zhuanjiaQushiquerenMapper;

    @Autowired
    private ZhuanjiaBiandongDetailMapper zhuanjiaBiandongDetailMapper;

    @Autowired
    private ZhuanjiaQushiquerenPiciMapper zhuanjiaQushiquerenPiciMapper;

    /**
     * 查询专家去世确认
     * 
     * @param id 专家去世确认主键
     * @return 专家去世确认
     */
    @Override
    public ZhuanjiaQushiqueren selectZhuanjiaQushiquerenById(String id)
    {
        return zhuanjiaQushiquerenMapper.selectZhuanjiaQushiquerenById(id);
    }

    /**
     * 查询专家去世确认列表
     * 
     * @param zhuanjiaQushiqueren 专家去世确认
     * @return 专家去世确认
     */
    @Override
    public List<ZhuanjiaQushiqueren> selectZhuanjiaQushiquerenList(ZhuanjiaQushiqueren zhuanjiaQushiqueren)
    {
        return zhuanjiaQushiquerenMapper.selectZhuanjiaQushiquerenList(zhuanjiaQushiqueren);
    }

    /**
     * 新增专家去世确认
     * 
     * @param zhuanjiaQushiqueren 专家去世确认
     * @return 结果
     */
    @Override
    public int insertZhuanjiaQushiqueren(ZhuanjiaQushiqueren zhuanjiaQushiqueren)
    {
        return zhuanjiaQushiquerenMapper.insertZhuanjiaQushiqueren(zhuanjiaQushiqueren);
    }

    /**
     * 修改专家去世确认
     * 
     * @param zhuanjiaQushiqueren 专家去世确认
     * @return 结果
     */
    @Override
    public int updateZhuanjiaQushiqueren(ZhuanjiaQushiqueren zhuanjiaQushiqueren)
    {
        return zhuanjiaQushiquerenMapper.updateZhuanjiaQushiqueren(zhuanjiaQushiqueren);
    }

    /**
     * 批量删除专家去世确认
     * 
     * @param ids 需要删除的专家去世确认主键
     * @return 结果
     */
    @Override
    public int deleteZhuanjiaQushiquerenByIds(String ids)
    {
        return zhuanjiaQushiquerenMapper.deleteZhuanjiaQushiquerenByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除专家去世确认信息
     * 
     * @param id 专家去世确认主键
     * @return 结果
     */
    @Override
    public int deleteZhuanjiaQushiquerenById(String id)
    {
        return zhuanjiaQushiquerenMapper.deleteZhuanjiaQushiquerenById(id);
    }

    public List<Map<String,Object>> findCustomList(String ppDeptId, String ppXingming, String ppSuoshudanwei, String ppShenfenzhenghao, int ppSiwangbiaoji, int ppShifouchuli, int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        ppXingming = "%"+ppXingming+"%";
        ppSuoshudanwei = "%"+ppSuoshudanwei+"%";
        return zhuanjiaQushiquerenMapper.findCustomList(ppDeptId,ppXingming,ppSuoshudanwei,ppShenfenzhenghao,ppSiwangbiaoji,ppShifouchuli,mmStartIndex,ppPageSize);
    }

    public int countCustomList(String ppDeptId,String ppXingming,String ppSuoshudanwei,String ppShenfenzhenghao,int ppSiwangbiaoji,int ppShifouchuli){
        ppXingming = "%"+ppXingming+"%";
        ppSuoshudanwei = "%"+ppSuoshudanwei+"%";
        return zhuanjiaQushiquerenMapper.countCustomList(ppDeptId,ppXingming,ppSuoshudanwei,ppShenfenzhenghao,ppSiwangbiaoji,ppShifouchuli);
    }

    /**
     * @param ppDeptId
     * @param ppXingming
     * @param ppSuoshudanwei
     * @param ppShenfenzhenghao
     * @param ppSiwangbiaoji
     * @param ppShifouchuli
     * @param ppPageIndex
     * @param ppPageSize
     * @return
     */
    @Override
    public List<Map<String, Object>> xiajidanweiqushilist(String ppDeptId, String ppXingming, String ppSuoshudanwei, String ppShenfenzhenghao, String ppSiwangbiaoji, int ppShifouchuli, int ppPageIndex, int ppPageSize) {
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return zhuanjiaQushiquerenMapper.xiajidanweiqushilist(ppDeptId,ppXingming,ppSuoshudanwei,ppShenfenzhenghao,ppSiwangbiaoji,ppShifouchuli,mmStartIndex,ppPageSize);
    }
    public int countxiajidanweiqushilist(String ppDeptId,String ppXingming,String ppSuoshudanwei,String ppShenfenzhenghao,String ppSiwangbiaoji,int ppShifouchuli){
        return zhuanjiaQushiquerenMapper.countxiajidanweiqushilist(ppDeptId,ppXingming,ppSuoshudanwei,ppShenfenzhenghao,ppSiwangbiaoji,ppShifouchuli);
    }

    /**
     * @return
     */
    @Override
    public Map<String,Integer> CountDeptandZhuanjia() {
        return zhuanjiaQushiquerenMapper.CountDeptandZhuanjia();
    }

    /**
     * @param piciid
     * @param danweimingcheng
     * @param danweicengji
     * @param zhuanjiaxingming
     * @param gongzuodanwei
     * @param shifoubiandong
     * @param shifouchuli
     * @param chuliriqi
     * @param pageindex
     * @param pagesize
     * @return
     */
    @Override
    public List<Map<String, Object>> qushiListBypiciid(String piciid, String danweimingcheng,
                                                       String danweicengji, String zhuanjiaxingming,
                                                       String gongzuodanwei, String shifoubiandong,
                                                       String shifouchuli, String chuliriqi,
                                                       int pageindex, int pagesize) {
        int mmStartIndex = (pageindex - 1) * pagesize;
        return zhuanjiaQushiquerenMapper.qushiListBypiciid(piciid,danweimingcheng, danweicengji,
                zhuanjiaxingming, gongzuodanwei, shifoubiandong,
                shifouchuli, chuliriqi, mmStartIndex, pagesize);
    }

    /**
     * @param piciid
     * @param danweimingcheng
     * @param danweicengji
     * @param zhuanjiaxingming
     * @param gongzuodanwei
     * @param shifoubiandong
     * @param shifouchuli
     * @param chuliriqi
     * @return
     */
    @Override
    public int countqushiListBypiciid(String piciid, String danweimingcheng,
                                      String danweicengji, String zhuanjiaxingming,
                                      String gongzuodanwei, String shifoubiandong,
                                      String shifouchuli, String chuliriqi){
        return  zhuanjiaQushiquerenMapper.countqushiListBypiciid(piciid,danweimingcheng, danweicengji,
                zhuanjiaxingming, gongzuodanwei, shifoubiandong,
                shifouchuli, chuliriqi);
    }

    /**
     * @param jigoudaima
     * @param danweimingcheng
     * @param danweicengji
     * @param zhuanjiaxingming
     * @param gongzuodanwei
     * @param shifoubiandong
     * @param shifouchuli
     * @param chuliriqi
     * @param pageindex
     * @param pagesize
     * @return
     */
    @Override
    public List<Map<String, Object>> qushiList(String jigoudaima, String danweimingcheng,
                                                       String danweicengji, String zhuanjiaxingming,
                                                       String gongzuodanwei, String shifoubiandong,
                                                       String shifouchuli, String chuliriqi,
                                                       int pageindex, int pagesize) {
        int mmStartIndex = (pageindex - 1) * pagesize;
        return zhuanjiaQushiquerenMapper.qushiList(jigoudaima,danweimingcheng, danweicengji,
                zhuanjiaxingming, gongzuodanwei, shifoubiandong,
                shifouchuli, chuliriqi, mmStartIndex, pagesize);
    }

    /**
     * @param jigoudaima
     * @param danweimingcheng
     * @param danweicengji
     * @param zhuanjiaxingming
     * @param gongzuodanwei
     * @param shifoubiandong
     * @param shifouchuli
     * @param chuliriqi
     * @return
     */
    @Override
    public int countqushiList(String jigoudaima, String danweimingcheng,
                                      String danweicengji, String zhuanjiaxingming,
                                      String gongzuodanwei, String shifoubiandong,
                                      String shifouchuli, String chuliriqi){
        return  zhuanjiaQushiquerenMapper.countqushiList(jigoudaima,danweimingcheng, danweicengji,
                zhuanjiaxingming, gongzuodanwei, shifoubiandong,
                shifouchuli, chuliriqi);
    }
    @Override
    @Transactional
    public boolean addZhuanjiaQushiAndBiandong(ZhuanjiaQushiqueren ppQushiqueren, ZhuanjiaBiandongDetail ppBiandong, ZhuanjiaQushiquerenPici ppPici){
        int addQushiqueren = this.insertZhuanjiaQushiqueren(ppQushiqueren);
        System.out.println(addQushiqueren);
        if (addQushiqueren!=1){
            throw new RuntimeException("去世确认添加失败");
        }

        int addBiandong = zhuanjiaBiandongDetailMapper.insertZhuanjiaBiandongDetail(ppBiandong);
        System.out.println(addBiandong);
        if (addBiandong!=1){
            throw new RuntimeException("变动添加失败");
        }

        int modifyPici = zhuanjiaQushiquerenPiciMapper.updateZhuanjiaQushiquerenPici(ppPici);
        if (modifyPici!=1){
            throw new RuntimeException("批次修改失败");
        }

        return true;
    }
}
